package com.yxw.yxnet_cd_center.common.utils;

import ch.qos.logback.classic.pattern.ClassicConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;
import com.yxw.yxnet_cd_center.common.constant.CommonConstant;
import org.slf4j.MDC;

import java.util.UUID;

/**
 * @desc: 将客户端送的keep打印在日志中，如果获取不到则获取一个UUID
 * @program: yxw1.0
 * @author: qlinc com.yxw.user.utils.KeepConvert
 * @date: 2022-10-17 09:05:23
 */
public class KeepConvert extends ClassicConverter {
    @Override
    public String convert(ILoggingEvent event) {
        String keep = MDC.get(CommonConstant.TRACE_LOG_ID);
        if (keep != null) {
            return keep;
        }
        return UUID.randomUUID().toString();
    }
}

